package stegnos.tests;

import org.quark.stegnos.Steganos;

import processing.core.PApplet;
import processing.core.PImage;

public class StegTest001 extends PApplet{

	final String filepath = "steg/";

	PImage carrier, burden, stegan, extract;
	Steganos steg;
	String s0 = "mary had a little lamb its fleece as white a snow";
	String s1 = "mary had a little lamb its fleece as white a snow";

	public void setup(){
		size(1000,660);
		background(220,220,250);

		int test = 1;
		
		switch(test){
		case 0:
			testImgImg("RGB Carrier <> RGB image burden", "crr_rgb.gif", "bdn_rgb_m.gif" );
			break;
		case 1:
			testImgImg("RGB Carrier <> ARGB image burden", "crr_rgb.gif", "bdn_argb_m.gif" );
			break;
		case 2:
			testImgImg("ARGB Carrier <> RGB image burden", "crr_argb.gif", "bdn_rgb_m.gif" );
			break;
		case 3:
			testImgImg("ARGB Carrier <> ARGB image burden", "crr_argb.gif", "bdn_argb_m.gif" );
			break;
		case 4:
			testImgImg("RGB Carrier <> large RGB image burden", "crr_rgb.gif", "bdn_rgb_l.gif" );
			break;
		case 5:
			testImgImg("RGB Carrier <> large ARGB image burden", "crr_rgb.gif", "bdn_argb_l.gif" );
			break;
		case 6:
			testImgImg("ARGB Carrier <> large RGB image burden", "crr_argb.gif", "bdn_rgb_l.gif" );
			break;
		case 7:
			testImgImg("ARGB Carrier <> large ARGB image burden", "crr_argb.gif", "bdn_argb_l.gif" );
			break;

		case 100:
			testImgTxt("RGB Carrier <> text burden", "crr_rgb.gif", "ampoem.txt" );
			break;
		case 101:
			testImgTxt("ARGB Carrier <> text burden", "crr_argb.gif", "ampoem.txt" );
			break;
			
		case 900:
			testImgImgTxt("RGB Carrier <> RGB burden <> Text", "crr_argb.gif", "bdn_argb_m.gif", "ampoem.txt" );
			break;
		}
	}

	public void textFileLoad(){
		PImage stegan = loadImage(filepath + "textburden.jpg");
		String extracted = Steganos.extractText(s1, stegan);
		System.out.println(extracted);
	}

	public void testImgImg(String title, String env, String ins){
		fill(0);
		textSize(16);
		text(title, (width - textWidth(title))/2, 24);
		// Load carrier
		carrier = loadImage(filepath + env);
		image(carrier, 10, 40);
		// Load burden
		burden = loadImage(filepath + ins);
		image(burden, 10, 400);
		// Make stegan
		stegan = Steganos.embedImage(s0, carrier, burden);
		image(stegan, 510, 40);
		// Extract burden
		extract = Steganos.extractImage(s1, stegan);
		image(extract, 510, 400);
	}

	public void testImgTxt(String title, String env, String ins){
		fill(0);
		textSize(16);
		text(title, (width - textWidth(title))/2, 24);
		// Load carrier
		carrier = loadImage(filepath + env);
		image(carrier, 10, 40);
		// Load burden
		String[] lines = loadStrings(filepath + ins);
		String burden = join(lines, "\n");
		// Make stegan
		stegan = Steganos.embedText(s0, carrier, burden);
		image(stegan, 510, 40);
		// Extract burden
		String extract = Steganos.extractText(s1, stegan);
		System.out.println(extract);

	}

	

	public void testImgImgTxt(String title, String env, String env1, String ins){
		fill(0);
		textSize(16);
		text(title, (width - textWidth(title))/2, 24);
		// Carrier
		carrier = loadImage(filepath + env);
		image(carrier, 10, 40);
		// Load image burden
		burden = loadImage(filepath + env1);
		image(burden, 10, 400);
		// Load text into inner burden
		String[] lines = loadStrings(filepath + "ampoem.txt");
		String p = join(lines, "\n");
		burden = Steganos.embedText(s0, burden, p);
		// Merge carrier with inner burden
		stegan = Steganos.embedImage(s0, carrier, burden);
		image(carrier, 510, 40);
		// Now extract inner image burden
		extract = Steganos.extractImage(s1, stegan);
		image(extract, 510, 400);
		// Now extract text
		String poem = Steganos.extractText(s1, extract);
		System.out.println(poem);
		
	}
	
	public void title(String t){
		float px = (width - textWidth(t))/2;
		fill(0);
		text(t, px, 16);
	}

}
